
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for block_user.
	''' </summary>
	Public Partial Class block_user
		Inherits BaseWebPage
		Protected htPageConstants As New Hashtable()

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			' this.pageTemplate.PageTitle = PageTitles.BLOCK_USER_PAGE;

			' init page from XML
			Me.initPageTitles(Constants.BLOCK_USER, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			Dim usr As User = Me.LoggedUser
			If usr = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			btnCancel.Attributes("onclick") = "javascript: history.back(); return false;"

			lblBlockUserMessage.Visible = False
			lblBlockYourself.Visible = False

			' hide user details control
			trUserShortCut.Visible = False

			Try
				Dim id As Integer = Convert.ToInt32(Request.Params("id"))
				Dim userToBlock As User = Users.GetUserByID(id)

				If userToBlock = Nothing Then
					lblBlockUserMessage.Text = Me.GetPageConstText(htPageConstants, "CONST_MsgUserNotExist_TEXT")
					lblBlockUserMessage.Visible = True
					btnBlockUser.Visible = False
					btnCancel.Visible = False
				Else
					If userToBlock.ID = LoggedUser.ID Then
						lblBlockYourself.Visible = True
						btnBlockUser.Visible = False
						btnCancel.Visible = False
					Else
						lblBlockUserMessage.Text = (Me.GetPageConstText(htPageConstants, "CONST_MsgQBlockUser_TEXT")).Replace("[PARAM]", userToBlock.Name)
						lblBlockUserMessage.Visible = True
						ucMemberShortcut.UserID = id
						trUserShortCut.Visible = True
					End If
				End If
			Catch
				lblBlockUserMessage.Text = Me.GetPageConstText(htPageConstants, "CONST_MsgError_TEXT")
				lblBlockUserMessage.Visible = True
				btnBlockUser.Visible = False
				btnCancel.Visible = False
			End Try
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()

		End Sub
#End Region

		Protected Sub btnBlockUser_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Dim usr As User = Me.LoggedUser
			Try
				Dim id As Integer = Convert.ToInt32(Request.Params("id"))
				Dim userToBlock As User = Users.GetUserByID(id)
				If userToBlock <> Nothing Then
					If usr.BlockedUsers.Contains(userToBlock.ID) Then
						lblBlockUserMessage.Visible = True
						lblBlockUserMessage.Text = Me.GetPageConstText(htPageConstants, "CONST_MsgUserBlocked_TEXT")
					Else
						usr.BlockedUsers.Add(New BO.BlockedUser(usr.ID, userToBlock.ID))
						lblBlockUserMessage.Visible = True
						lblBlockUserMessage.Text = Me.GetPageConstText(htPageConstants, "CONST_MsgBlockSuccess_TEXT")
						Response.Redirect(Constants.VIEW_BLOCKED_USERS)
					End If
					btnBlockUser.Visible = False
					btnCancel.Visible = False
				End If
			Catch
				lblBlockUserMessage.Text = Me.GetPageConstText(htPageConstants, "CONST_MsgError_TEXT")
				lblBlockUserMessage.Visible = True
				btnBlockUser.Visible = False
				btnCancel.Visible = False
			End Try
		End Sub

		====================
        ' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
        Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
            Get
                Return Migrated_Form1
            End Get
        End Property
        'set { Migrated_Form1 = value; }
    End Class
End Namespace






